using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace insertLink
{
    public partial class frmLink : Form
    {
        string link;
        string text;
        string newWindow;

        public frmLink(string link)
        {
            this.link = link;
            InitializeComponent();
            txbxLinkURL.Text = link;
            this.Controls.Add(txbxLinkText);
            this.Controls.Add(txbxTitle);
            txbxLinkText.KeyPress += new KeyPressEventHandler(keypressed);
            txbxTitle.KeyPress +=new KeyPressEventHandler(keypressed);
        }

        void keypressed(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)Keys.Escape)
            {
                button2_Click(this, null);
            }
            else if (e.KeyChar == (char)Keys.Enter)
            {
                button1_Click(this, null);
            }
        }

        public string getText
        {
            get { return text; }
        }
        

        private void button1_Click(object sender, EventArgs e)
        {
            if (checkBox1.Checked == true)
                newWindow = " target=\"_blank\"";
            else
                newWindow = "";

            text = "<a href=\"" + link + "\" title=\"" + txbxTitle.Text + "\"" + newWindow + ">" + txbxLinkText.Text + "</a>";
            DialogResult = DialogResult.OK;
            this.Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}